package br.com.conceito.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class FabricaDAO {

	private static final FabricaDAO INSTANCIA = new FabricaDAO();
	
	private Connection connection;
	
	 private FabricaDAO() {}
	 
	 public static FabricaDAO getInstancia(){
		 return INSTANCIA;
	 }
	 
	 public Connection getConection() throws SQLException, ClassNotFoundException{
		 if(connection == null || connection.isClosed()){
			 Class.forName("com.mysql.jdbc.JDBC4Connection");
			 connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ceu", "root", "root");
		 }
		 return connection;
	 }
	 
	 public static void main(String[] args) {
		try {
			StringBuffer sql = new StringBuffer();
			sql.append("update ceu.arvore set nome = 'Inicio dos arquivo 2' where id = 2");
			Connection connection = FabricaDAO.getInstancia().getConection();
			PreparedStatement statement = connection.prepareStatement(sql.toString());
			statement.execute();
//			while(rs.next()){
//				System.out.println(rs.getString("nome"));
//			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
